# -*- encoding:utf-8 -*-
'''
	videodao.py
	======================
	@descript: 
	@copyright:chinasoft
	@author:guoxiaofei
	@date: 2021-01-27 15:06
	@version:v1.0
'''
from entity.videoentity import VideoEntity
from tool.pymysqltool import PyMysqlTool
class VideoDao:
    def __init__(self):
        #  获取数据库连接对象
        self.__pyMysqlToo=PyMysqlTool()
        pass
    def insertable(self,videoentity:VideoEntity):
        '''

        :param videoentity: 插入的电视剧信息
        :return: var_result  : 所影响的行数
        '''
        with self.__pyMysqlToo as var_cursor:
            var_sql='INSERT INTO videotable(id,videoname,videourl,videoimage) VALUES (NULL,%s,%s,%s);'
            var_result=var_cursor.execute(var_sql,(videoentity.videoname,videoentity.videourl,videoentity.videoimage))
        return var_result
        pass

    def updatetable(self, videoentity: VideoEntity):
        '''

        :param videoentity: 更新的电视剧信息
        :return:
        '''
        return
        pass

    def deletetable(self, videoentity: VideoEntity):
        '''

        :param videoentity: 删除的电视剧信息
        :return:
        '''
        return
        pass

    def selecttable(self):
        '''

        :param videoentity: 查看的电视剧信息
        :return:
        '''
        # 定义一个空列表，用来保存查询的数据库元素
        var_VideoEntity_List = []
        # 获取数据库操作对象 游标
        with self.__pyMysqlToo as var_cursor:
            # 通过数据库操作对象操作数据库
            var_sql = 'SELECT id,videoname,videourl,videoimage FROM videotable'
            # 返回结果为查询到的记录数
            var_result = var_cursor.execute(var_sql)
            print('查询到的记录数为：', var_result, '。')
            var_dict_list = var_cursor.fetchall()
            for element in var_dict_list:
                var_VideoEntity = VideoEntity(**element)
                var_VideoEntity_List.append(var_VideoEntity)
                pass
            pass
        return var_VideoEntity_List

    pass